#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
using namespace std;
void test1()
{
	string s2("hello worldxxxxxxxxxxxxx");
	cout << s2.size() << endl;
	cout << s2.capacity() << endl << endl;

	s2.reserve(20);
	cout << s2.size() << endl;
	cout << s2.capacity() << endl << endl;

	s2.reserve(28);
	cout << s2.size() << endl;
	cout << s2.capacity() << endl << endl;

	s2.reserve(40);
	cout << s2.size() << endl;
	cout << s2.capacity() << endl << endl;

	s2.clear();
	cout << s2.size() << endl;
	cout << s2.capacity() << endl << endl;

	cout << typeid(string::iterator).name() << endl;
	cout << typeid(string::reverse_iterator).name() << endl;
}
void stringtest()
{
	string s1("Hello world");
	s1.push_back('x');
	cout << s1 << endl;

	string s2;
	s2.append(s1.begin(), s1.end());
	cout << s2 << endl;

	s2 += s1;
	cout << s2 << endl;

	string s3("hello bit");
	s3.insert(0, s1);
	cout << s3 << endl;

	s3.insert(s3.begin(), s1.begin(), s1.end());
	cout << s3 << endl;

	s3.erase();
	cout << s3 << endl;
}

void stringtest2()
{
	string s1("hello                           world");
	//s1.replace(4, 3, "xxxxxxxxxxxx");
	cout << s1 << endl;

	/*size_t ret=s1.find(' ');
	while (ret != std::string::npos)
	{
		s1.replace(ret, 2, "##");
		ret = s1.find(' ', ret + 1);
		cout << s1 << endl;
	}
	cout << s1 << endl;*/

	string tmp;
	tmp.reserve(s1.capacity());
	for (auto ret : s1)
	{
		if (ret == ' ')
		{
			tmp += "##";
		}
		else
		{
			tmp += ret;
		}
	}
	s1.swap(tmp);
	cout << s1 << endl;

	string file;
	cin >> file;
	FILE* fout = fopen(file.c_str(), "r");
	char ch = fgetc(fout);
	while (ch != EOF)
	{
		cout << ch;
		ch = fgetc(fout);
	}
	cout << endl;
	fclose(fout);
}
void stringtest3()
{
	string s1("hello bit");
	size_t ret=s1.find("hello");
	string s2=s1.substr(ret);
	cout << s2 << endl;

	cout << s1 + "aaaa" << endl;
	cout << "bbbbb" + s1 << endl;

	size_t found=s1.find_first_of("ellb");
	while (found != std::string::npos)
	{
		s1[found] = '#';
		found = s1.find_first_of("ellb");
	}
	cout << s1 << endl;
}
int main()
{
	stringtest3();
	return 0;
}